import React from 'react'
import {
	Text, View
} from "react-native";
import { SpaceBetween } from '../../../create/_components/SpaceBetween.js';
import { CURRENCY } from '../../../../../utils/helper';
import MethodUtil from '../../../../../utils/MethodUtil';
import { styles } from '../../_common/style';
import { style } from '../../../../../theme/style';

//商品信息
export const QHSaleItemSection = (props) => {
	const { data } = props;
	const { currency, orderItemList } = data;

	return (
		orderItemList && orderItemList.length > 0 ?
			orderItemList.map((item, index) => {
				let endAddress = '';
				endAddress = item.endAddressList ? item.endAddressList.map((addj, j) => {
					const addressEnd = (addj.provinceName || '') + (addj.cityName || '') + (addj.areaName || '') + (addj.addressName ? addj.addressName : (addj.detailAddress || ''));
					return addressEnd + (j === (item.endAddressList.length - 1) ? '' : '，');
				}) : '';
				return (
					<View key={index} style={[styles.itemBox, styles.borders]}>
						<Text style={styles.itemTitle}>{item.goodsName}</Text>
						<SpaceBetween fontLeft={{ title: '数量' }} fontRight={{ title: item.quantity + item.uomName }} />
						<SpaceBetween fontLeft={{ title: '价格' }} fontRight={{ title: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(item.price || 0, 2) + CURRENCY.getUnit(currency).text + '/' + item.uomName }} />
						<SpaceBetween fontLeft={{ title: '计价公式' }} fontRight={{ title: item.tempPriceFormulaDesc || '-' }} />
						{endAddress.length > 0 ? <SpaceBetween fontLeft={{ title: '目的地' }} fontRight={{ title: endAddress || '-' }} /> : null}
						{item.logisticsPrice ? <SpaceBetween fontLeft={{ title: '运费' }} fontRight={{ title: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(item.logisticsPrice, 2) + CURRENCY.getUnit(currency).text + '/' + item.uomName }} /> : null}
						<SpaceBetween fontLeft={{ title: '客户优惠' }} fontRight={{ title: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(item.rebatePrice || 0, 2) + CURRENCY.getUnit(currency).text + '/' + item.uomName }} />
						<SpaceBetween fontLeft={{ title: '升贴水' }} fontRight={{ title: (item.udPrice >= 0 ? '+' : '') + item.udPrice + CURRENCY.getUnit(currency).text }} />
						<View style={styles.viewWidthTopBorder}>
							<SpaceBetween fontLeft={{ title: '订单总价' }} fontRight={{ title: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(item.amount || 0, 2) + CURRENCY.getUnit(currency).text, style: { color: style.color.pink } }} />
						</View>
					</View >
				)
			}) : null
	)
}